using System;
using System.Configuration;
using System.IO;
using System.Reflection;
using ExtensionMethods;

namespace HardwareUtils
{
    public class DevCon
    {
         public static ShellExe RestartDevice(string deviceid)
        {
            var path = GetDevConPath();
            var r1 = ShellExe.ExecuteProgram(path, String.Format("restart \"@{0}\"", deviceid));
            return r1;
        }

       public static ShellExe RemoveDevice(string deviceid)
        {
            var path = GetDevConPath();
            var r1 = ShellExe.ExecuteProgram(path, String.Format("remove \"@{0}\"", deviceid));
            return r1;
        }


        public static ShellExe RescanDevices()
        {
            var path = GetDevConPath();
            var r2 = ShellExe.ExecuteProgram(path, String.Format("rescan"));
            return  r2 ;
        }

        public static string GetDevConPath ()
        {
            var rootPath = EnvironmentUtils.RootPath(ConfigurationManager.AppSettings["rootDirPrefix"] + ConfigurationManager.AppSettings["devConPath"]);
            string dirpath = rootPath + "\\" + (Environment.Is64BitOperatingSystem ? "ia64" : "i386");
            dirpath = dirpath.Replace(@"\\", @"\");
            var path = dirpath + @"\devcon.exe";
            return path;
        }
    }
}